<template>
  <div class="app-container">
    <el-form @submit.native.prevent :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="getSettlementStatement" label-width="120px" :label-position="labelPosition">
      <el-form-item label="客户" prop="khm">
        <el-select
            v-model="queryParams.khm"
            placeholder="请输入客户"
            clearable
            @change="changeSelectClient3"
            filterable
            :loading="selectClient3Loading"
        >
            <el-option
                v-for="(item, index) in client3List"
                :key="index"
                :label="item.khmc"
                :value="item.khmc"
            />
        </el-select>
      </el-form-item>
      <el-form-item label="柜号/批号" prop="spgh">
        <el-input
          v-model="queryParams.spgh"
          placeholder="请输入柜号/批号"
          clearable
          @keyup.enter.native="enterClick"
        />
      </el-form-item>
       <el-form-item label="仓库" prop="spckmc">
        <el-input
          v-model="queryParams.spckmc"
          placeholder="请输入仓库"
          clearable
          @keyup.enter.native="enterClick"
        />
      </el-form-item>
       <el-form-item label="条码" prop="sptm">
        <el-input
          v-model="queryParams.sptm"
          placeholder="请输入条码"
          clearable
          @keyup.enter.native="enterClick"
        />
      </el-form-item>
      <el-form-item label="所选日期" prop="warehousePropertyDetailDate">
        <el-date-picker
          v-model="warehousePropertyDetailDate"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="warehousePropertyDetailDateChange()">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="getList">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8" v-show="getSettlementStatement">
        <el-col :span="1.5">
          <el-button type="primary" plain size="mini" @click="handleExport" v-hasPermi="['zhcloud:sjzl:export']">导出Excel</el-button>
        </el-col>
    </el-row>
    <el-table
      v-loading="loading"
      :data="warehousePropertyDetailList"
    >
      <af-table-column prop="sptm" label="客户条码"></af-table-column>
      <af-table-column prop="sptmc" label="仓库条码"></af-table-column>
      <af-table-column prop="spzs" label="物品规格"></af-table-column>
      <af-table-column prop="spgh" label="柜号"></af-table-column>
      <af-table-column prop="spbh" label="批号"></af-table-column>
      <af-table-column prop="spcd" label="品牌"></af-table-column>
      <af-table-column prop="spckmc" label="仓库"></af-table-column>
      <af-table-column prop="allName" label="客户"></af-table-column>
      <af-table-column prop="ssrqid" label="入仓日期"></af-table-column>
      <af-table-column prop="xm" label="项目"></af-table-column>
      <af-table-column prop="bzdj" label="收费单价"></af-table-column>
      <af-table-column prop="bz" label="收费类型"></af-table-column>
      <af-table-column prop="rqid" label="发生日期"></af-table-column>
      <af-table-column prop="spsl" label="作业吨数"></af-table-column>
      <af-table-column prop="sfje" label="增值服务费用"></af-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="pageNum"
      :limit.sync="pageSize"
      @pagination="getList"
    />
  </div>

</template>

<script>
import { getWarehousePropertyDetailList } from "@/api/storage/dataOverview/settlementStatement";
import { selectClient3 } from "@/api/storage/customer"

export default {
  name: "WarehousePropertyDetailList",
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      //表格加载
      loading:true,
       //对齐
      labelPosition: "right",
       //类型
       type: "",
      //客户加载
      selectClient3Loading:true,
      warehousePropertyDetailDate:'',
      // 查询参数
      queryParams: {
        e1: "",
        e2: "",
        e3: "",
        khm: "",
        spckmc: "",
        spgh: "",
        spkhmcid: "",
        sptm: "",
        downloadType:"json"
      },
      //获取客户参数
      selectClient3Query: {
        name1:""
      },
      // 增值服务列表
      warehousePropertyDetailList: [],
      //客户列表
      client3List: [],
      //页数
      pageSize: 10,
      //页码
      pageNum:1,
      // 总条数
      total: 0,
    };
  },
  beforeRouteEnter(to, from, next) {
    next(vm => {   
      const query = to.query
      vm.type = query.type
      vm.queryParams = query.data
      vm.getList()
    })
  },
  created() {
    this.getClient3()
  },
  computed: {
    getSettlementStatement() {
      return this.type == "settlementStatement"?false:true
    }
  },
  methods: {
     /**获取客户 */
    getClient3() {
      this.selectClient3Loading = true
      selectClient3(this.selectClient3Query).then(response => {
        this.client3List = response.data
        this.selectClient3Loading = false
      });
    },

    /** 增值服务 */
    getList() {
      this.loading = true
      getWarehousePropertyDetailList(this.queryParams, {pageNum:this.pageNum, pageSize:this.pageSize}).then(response => {
        this.warehousePropertyDetailList = response.rows;
        this.total = response.total;
        this.loading = false
      });
    },

    /**选择客户 */
    changeSelectClient3() {
        this.getList()
    },

     /**选择日期 */
    warehousePropertyDetailDateChange() {
      this.queryParams.e1 = this.warehousePropertyDetailDate?this.warehousePropertyDetailDate[0]:""
      this.queryParams.e2 = this.warehousePropertyDetailDate?this.warehousePropertyDetailDate[1]:""
      this.getList()
    },

    /** 导出所需数据*/
    handleExport() {
      this.download('/storage/sjzl/valueAddedServiceDetailsExport', this.queryParams, `增值服务明细_${new Date().getTime()}.xlsx`)
    },

    /**enter键触发 */
    enterClick(e) {
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.reset()
      this.getClient3()
      this.getList()
    },
    reset() {
      Object.assign(this.$data, this.$options.data())
    },
  }
};
</script>
